package com.cxxx.guns.modular.backend.controller;

import com.cxxx.guns.core.base.controller.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.beans.factory.annotation.Autowired;
import com.cxxx.guns.core.log.LogObjectHolder;
import org.springframework.web.bind.annotation.RequestParam;
import com.cxxx.guns.modular.system.model.LeaveMessage;
import com.cxxx.guns.modular.backend.service.ILeaveMessageService;

/**
 * 留言中心控制器
 *
 * @author fengshuonan
 * @Date 2018-09-14 14:58:49
 */
@Controller
@RequestMapping("/leaveMessage")
public class LeaveMessageController extends BaseController {

    private String PREFIX = "/backend/leaveMessage/";

    @Autowired
    private ILeaveMessageService leaveMessageService;

    /**
     * 跳转到留言中心首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "leaveMessage.html";
    }

    /**
     * 跳转到添加留言中心
     */
    @RequestMapping("/leaveMessage_add")
    public String leaveMessageAdd() {
        return PREFIX + "leaveMessage_add.html";
    }

    /**
     * 跳转到修改留言中心
     */
    @RequestMapping("/leaveMessage_update/{leaveMessageId}")
    public String leaveMessageUpdate(@PathVariable Integer leaveMessageId, Model model) {
        LeaveMessage leaveMessage = leaveMessageService.selectById(leaveMessageId);
        model.addAttribute("item",leaveMessage);
        LogObjectHolder.me().set(leaveMessage);
        return PREFIX + "leaveMessage_edit.html";
    }
    @RequestMapping("/leaveMessage_detail/{leaveMessageId}")
    public String leaveMessageDetail(@PathVariable Integer leaveMessageId, Model model) {
        LeaveMessage leaveMessage = leaveMessageService.selectById(leaveMessageId);
        model.addAttribute("item",leaveMessage);
        LogObjectHolder.me().set(leaveMessage);
        return PREFIX + "leaveMessage_detail.html";
    }


    /**
     * 获取留言中心列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
        return leaveMessageService.selectList(null);
    }

    /**
     * 新增留言中心
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(LeaveMessage leaveMessage) {
        leaveMessageService.insert(leaveMessage);
        return SUCCESS_TIP;
    }

    /**
     * 删除留言中心
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer leaveMessageId) {
        leaveMessageService.deleteById(leaveMessageId);
        return SUCCESS_TIP;
    }

    /**
     * 修改留言中心
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(LeaveMessage leaveMessage) {
        leaveMessageService.updateById(leaveMessage);
        return SUCCESS_TIP;
    }

    /**
     * 留言中心详情
     */
    @RequestMapping(value = "/detail/{leaveMessageId}")
    @ResponseBody
    public Object detail(@PathVariable("leaveMessageId") Integer leaveMessageId) {
        return leaveMessageService.selectById(leaveMessageId);
    }
}
